package com.koma.mvpdemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.koma.mvpdemo.R;
import com.koma.mvpdemo.view.IMainView;
import com.koma.mvpdemo.presenter.MainPresenter;

/**
 * Created by chengengsen on 2016/9/30.
 */
public class MainActivity extends AppCompatActivity implements View.OnClickListener,IMainView{

    private EditText username;
    private EditText password;
    private Button btn;
    private String name;
    private String pwd;

    private MainPresenter mainPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        username = (EditText) findViewById(R.id.username);
        password = (EditText) findViewById(R.id.password);
        btn = (Button) findViewById(R.id.btn);

        btn.setOnClickListener(this);

        mainPresenter = new MainPresenter(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn:
                name = username.getText().toString();
                pwd = password.getText().toString();
                mainPresenter.login(name, pwd);
                break;
        }
    }

    @Override
    public void LoginSuccess() {

        Intent intent = new Intent(MainActivity.this, SecondActivity.class);
        intent.putExtra("name", name);
        intent.putExtra("password", pwd);
        startActivity(intent);

    }

    @Override
    public void LoginFailed(String msg) {
        Toast.makeText(MainActivity.this, msg,Toast.LENGTH_SHORT).show();
    }


}
